package com.sdl.test.flutter_sdl_test.surface_view

import android.content.Context
import android.graphics.PixelFormat
import android.view.SurfaceView
import android.view.View
import android.view.ViewGroup
import com.sdl.test.flutter_sdl_test.jni.SViewHolder
import io.flutter.plugin.platform.PlatformView


class MySurfaceViewGroup(
    private var realContext: Context,
): PlatformView {
    var surfaceView: SurfaceView = SurfaceView(realContext)
    val sHolder = SViewHolder()
    init {
        init()
    }

    private fun init() {


//        setBackgroundColor(Color.BLUE)
//        surfaceView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
//        surfaceView.setZOrderMediaOverlay(true)
//        surfaceView.holder.setFormat(PixelFormat.TRANSLUCENT)
        surfaceView.holder.addCallback(sHolder)

//        surfaceView.holder.addCallback(object: SurfaceHolder.Callback{
//            override fun surfaceCreated(holder: SurfaceHolder) {
//                val canvas = holder.lockCanvas()
//                try {
//                    // 设置背景颜色为白色
//                    Log.d("ssss", "11 - width:${canvas.width} height:${canvas.height}")
//                    canvas?.let {
//                        it.drawRect(0f, 0f, it.width.toFloat(), it.height.toFloat(),  Paint().apply {
//                            color = Color.BLACK
//                        })
//                    }
////                    canvas.drawColor(Color.BLUE)
//                    canvas.drawText("sssss", 500F,500F, Paint().apply {
//                        color = Color.BLUE
//                        textSize = 100F
//                    })
//                } finally {
//                    if (canvas != null) {
//                        holder.unlockCanvasAndPost(canvas)
//                    }
//                }
//            }
//
//            override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
//                Log.d("ssss", "width:$width height:$height")
//            }
//
//            override fun surfaceDestroyed(holder: SurfaceHolder) {
//            }
//        })
        // 可以在这里对你的SurfaceView进行初始化和设置
//        addView(surfaceView)
    }

    override fun getView(): View {
        return surfaceView
    }

    override fun dispose() {
        // 处理你的SurfaceView的销毁逻辑
    }

}